<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSX事件绑定-demo</title>
    <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script crossorigin src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <style>
        .active {
            color: red
        }
        li {
            cursor: pointer;
        }
    </style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
    const root = ReactDOM.createRoot(document.getElementById('root'))

    class App extends React.Component {
        constructor(props) {
            super();
            this.state = {
                movies: [
                    '大话西游',
                    '古惑仔-猛龙过江',
                    '肖申克的救赎'
                ],
                activeIndex: 0,
            }
        }

        btnClick(i) {
            this.setState({
                activeIndex: i,
            })
        }

        render() {
            const {activeIndex} = this.state;
            return (
                <div>
                    <h1>JSX事件绑定-demo</h1>
                    <ul>
                        {
                            this.state.movies.map((item, i) =>
                                <li
                                    className={activeIndex === i ? 'active' : ''} key={i}
                                    onClick={() => this.btnClick(i)}
                                >{item}</li>)
                        }
                    </ul>
                </div>
            )
        }
    }
    root.render(<App />);
</script>
</body>
</html>